﻿#include <elementtabwidget.h>
#include <ElementGraphicsView.h>
#include <ElementGraphicsCanvas.h>
using namespace std;

ElementTabWidget::ElementTabWidget(QWidget *parent)
    :QTabWidget(parent)
{
    // 事件绑定
    connect(this,&ElementTabWidget::tabCloseRequested,this,&ElementTabWidget::onTabCloseRequested);
}

ElementGraphicsView *ElementTabWidget::elementGraphicsView(int index)
{
    return static_cast<ElementGraphicsView *>(this->widget(index));
}

void ElementTabWidget::onTabCloseRequested(int index)
{
    ElementGraphicsView* w = static_cast<ElementGraphicsView*>(this->widget(index));
    if(w){
        this->removeTab(index);
        delete w;
    }
}

ElementGraphicsView *ElementTabWidget::addNewTab(const QIcon& tabIcon)
{
    ElementGraphicsView * view = new ElementGraphicsView(this);
    ElementGraphicsCanvas *canvas = new ElementGraphicsCanvas(QRectF(0,0,1000,1000),view);

    view->setScene(canvas);
    int index = this->addTab(view,QString("Project"));
    this->setTabIcon(index,tabIcon);
    return view;
}
